﻿//mapTools

var national=
{
    locale:'zh_cn',repLocale:function(str)
    {
        var localeStr=this.locale;
        if(localeStr=='zh_cn')localeStr='';
        else localeStr='_'+localeStr;
        str=str.replace(/!\{Locale\}/g,localeStr);
        return str;
    }
    ,getStr:function(type,child,rep)
    {
        var o=this.getLangData(type);
        if(o&&o[child]) return o[child];
        else if(rep) return rep;
        else return '';
    }
    ,getLangData:function(type)
    {
        if(typeof(o__language)!='object') o__language=
        {
        };
        return o__language[type];
    }
    ,convertStr:function(str,type)
    {
        var src=this.getLangData(type);
        return this.reStr(str,src);
    }
    ,reStr:function(str,src)
    {
        var mode=false;
        if(typeof(src)=='object')
        {
            this.src=src;
            mode=true;
        }
        var re=/%\{(\w+):(.*?)\}/g;
        if(mode)str=str.replace(re,this.matchStr.bind(this));
        else str=str.replace(re,this.matchStr2);
        return str;
    }
    ,formatStr:function(type,params)
    {
        var o=this.getLangData('Format');
        if(!o||!o[type]) return;
        this.src=params;
        var re=/#\{(\w+)\}/g;
        return o[type].replace(re,this.matchStr3.bind(this));
    }
    ,matchStr:function(mstr,m1,m2)
    {
        if(this.src[m1]) return this.src[m1];
        else return m2;
    }
    ,matchStr2:function(mstr,m1,m2)
    {
        return m2;
    }
    ,matchStr3:function(mstr,m1)
    {
        if(this.src[m1]) return this.src[m1];
        else return '';
    }
    ,showMsg:function(str)
    {
        var src=this.getLangData('Prompt');
        str=this.reStr(str,src);
        alert(str);
    }
};